//
//  CZBaseViewController.m
//  小和微博
//
//  Created by 董晓合 on 15/2/23.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "CZBaseViewController.h"
#import "CZNavigationController.h"
#import "CZOAuthViewController.h"
#import "CZAccount.h"

@interface CZBaseViewController ()<CZDefaultCenterViewDelegate>

@end

@implementation CZBaseViewController

- (void)loadView {

    // 取出存储的模型对象
    CZAccount *account = [CZAccount accountFromSandbox];
    
    // 判断是否已经授权
    if (account != nil) {
        // 已经授权
        [super loadView];
    }else
    {
        // 没有授权
        CZDefaultCenterView *defaultCenterView = [CZDefaultCenterView defaultCenterView];
        self.view = defaultCenterView;
        self.defaultCenterView = defaultCenterView;
        self.defaultCenterView.delegate = self;
    }
}

#pragma mark - CZDefaultCenterViewDelegate

- (void)defaultCenterView:(CZDefaultCenterView *)defaultCenterView didClickLogin:(UIButton *)loginBtn {

//    1.创建导航控制器
    CZNavigationController *nav = [[CZNavigationController alloc] init];
//    2.创建授权控制器
    CZOAuthViewController *OAuthVc = [[CZOAuthViewController alloc] init];
    [nav addChildViewController:OAuthVc];
//    3.弹出授权控制器
    [self presentViewController:nav animated:YES completion:nil];
    
}

- (void)defaultCenterView:(CZDefaultCenterView *)defaultCenterView didClickRegister:(UIButton *)registerBtn {

    DDActionLog;
}
@end
